package com.hcy.performancepro.controller.performanceTool;

import com.fuled.test.tool_config.DisableUtil;
import com.hcy.performancepro.bo.performanceTool.RecordControllerBo;
import com.hcy.performancepro.po.performanceTool.RecordController;
import com.hcy.performancepro.service.performanceTool.PerformanceToolControllerService;
import com.hcy.performancepro.util.ResultData;
import com.hcy.performancepro.vo.performanceTool.RecordControllerVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/performanceController")
@DisableUtil
@RequiredArgsConstructor
public class PerformanceToolControllerController {

    private final PerformanceToolControllerService performanceToolControllerService;

    @PostMapping("/page")
    public ResultData<Object> page(@RequestParam Integer currentPage, @RequestParam Integer pageSize, @RequestBody RecordControllerBo recordControllerBo){
        List<RecordController> list = performanceToolControllerService.sarchlist(currentPage, pageSize,recordControllerBo);
        List<RecordControllerVo> listVo = new ArrayList<>();
        if(list != null && !list.isEmpty()) {
            for (RecordController obj : list) {
                RecordControllerVo vo = new RecordControllerVo();
                BeanUtils.copyProperties(obj, vo);
                listVo.add(vo);
            }
        }
        return ResultData.ok(listVo);
    }


    @GetMapping("/count")
    public ResultData<Object> count(RecordControllerBo recordControllerBo){
        return ResultData.ok(performanceToolControllerService.countNumber(recordControllerBo));
    }
}